<template>
  <div class="body-container layout-padding">
    <div v-for="ckItem in state.cangKuList" style="height: 50px; border-bottom: 1px dashed #eebe77 ">
      <span class="cwhname">{{ckItem.cwhname}}</span>
      <el-switch v-model="ckItem.lock"  size="large" active-text="锁定盘点" inactive-text="开放盘点" @change="kcLockChange(ckItem.id)"  />
    </div>
  </div>
</template>

<script setup name="cangkulock">
import request from '/@/utils/request';
import { ElMessage } from 'element-plus';
import {reactive, ref, onMounted, onUnmounted, defineAsyncComponent} from "vue";

const state = reactive({
  cangKuList : [],
})
const searchUserCangKu = () =>{
  request({
    url: '/cangku/listuserwh',
    data: {}
  }).then(res => {
    const { data } = res
    state.cangKuList = data
    state.cangKuList.forEach(cangKuItem =>{
      cangKuItem.lock = cangKuItem.lockstatus === 1
    })
  })
}
const kcLockChange = (cangkuid)=>{
  const ckItem = state.cangKuList.find(item=>item.id===cangkuid)
  if(!ckItem){
    ElMessage.error(cangkuid+"不存在,未知错误")
    return
  }
  request({
    url: '/cangku/savecangkulock',
    data: {cangkuid : cangkuid, lockstatus: ckItem.lock ? 1 : 0}
  }).then(res => {

  })
}
onMounted(()=>{
  searchUserCangKu();
})
onUnmounted(()=>{

})
</script>

<style scoped lang="scss">
.cwhname{
  display: inline-block;
  width: 300px;
  margin-right: 20px;
  font-size: 14px;
  font-weight: bold;
}
</style>
